/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * @author Renato ferreira dos santos
 * Created on 06/04/2010, 08:48:08
 */

package rad.Java.MotelPlus.Entries;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import rad.Java.Common.Class.Person;
import rad.Java.Common.DB.Database;
import rad.Java.Common.List.Persons;
import rad.Java.Common.Util.Constants;
import rad.Java.Common.Util.Functions;

        
public class frmRegisterEmployee extends javax.swing.JFrame {

    // <editor-fold defaultstate="collapsed" desc="Declaration of variables">
        private Person employee = new Person();
        private Persons listEmployee = new Persons();
    // </editor-fold>

    /** Creates new form frmRegisterEmployee */
    public frmRegisterEmployee() {
        initComponents();
        buttons[0] = btnNew;
        buttons[1] = btnEdit;
        buttons[2] = btnSave;
        buttons[3] = btnDelete;
        buttons[4] = btnCancel;
        buttons[5] = btnExit;

        init();
        if( !resizeForm )
        {
            //this.MinimumSize = this.Size;
            //this.MaximumSize = this.Size;
        }

        _status = Constants.stBrowse;

        Functions.setButtons(buttons, _status);
        listEmployee.fillList();
        fillDataGridView();

        _title = this.getTitle(); //System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;


        if (!tabSearchVisible)
            pnlSearch.setVisible(false);

        if (!tabMainVisible)
            pnlEdit.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlFrame = new javax.swing.JPanel();
        pnlDefaultButtons = new javax.swing.JPanel();
        btnNew = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnExit = new javax.swing.JButton();
        pnlMain = new javax.swing.JPanel();
        tbpMain = new javax.swing.JTabbedPane();
        pnlSearch = new javax.swing.JPanel();
        lblSearch = new javax.swing.JLabel();
        txtSearch = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblMain = new javax.swing.JTable();
        btnSearch = new javax.swing.JButton();
        pnlEdit = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        txtPhone = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtDateBorn = new javax.swing.JFormattedTextField();
        jLabel5 = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtPasswordConf = new javax.swing.JPasswordField();
        jLabel7 = new javax.swing.JLabel();
        txtPassword = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        pnlFrame.setName("pnlFrame"); // NOI18N
        pnlFrame.setLayout(new java.awt.BorderLayout());

        pnlDefaultButtons.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pnlDefaultButtons.setMinimumSize(new java.awt.Dimension(341, 27));
        pnlDefaultButtons.setName("pnlDefaultButtons"); // NOI18N
        pnlDefaultButtons.setPreferredSize(new java.awt.Dimension(606, 70));
        pnlDefaultButtons.setRequestFocusEnabled(false);
        pnlDefaultButtons.setLayout(new java.awt.GridLayout(1, 0));

        btnNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rad/Java/Common/Resources/new_32x32.png"))); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(motelplus.MotelPlusApp.class).getContext().getResourceMap(frmRegisterEmployee.class);
        btnNew.setToolTipText(resourceMap.getString("btnNew.toolTipText")); // NOI18N
        btnNew.setName("btnNew"); // NOI18N
        btnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewActionPerformed(evt);
            }
        });
        pnlDefaultButtons.add(btnNew);

        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rad/Java/Common/Resources/save_32x32.png"))); // NOI18N
        btnSave.setToolTipText(resourceMap.getString("btnSave.toolTipText")); // NOI18N
        btnSave.setName("btnSave"); // NOI18N
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });
        pnlDefaultButtons.add(btnSave);

        btnEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rad/Java/Common/Resources/edit_32x32.png"))); // NOI18N
        btnEdit.setToolTipText(resourceMap.getString("btnEdit.toolTipText")); // NOI18N
        btnEdit.setName("btnEdit"); // NOI18N
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });
        pnlDefaultButtons.add(btnEdit);

        btnCancel.setIcon(resourceMap.getIcon("btnCancel.icon")); // NOI18N
        btnCancel.setText(resourceMap.getString("btnCancel.text")); // NOI18N
        btnCancel.setToolTipText(resourceMap.getString("btnCancel.toolTipText")); // NOI18N
        btnCancel.setName("btnCancel"); // NOI18N
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });
        pnlDefaultButtons.add(btnCancel);

        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rad/Java/Common/Resources/delete_32x32.png"))); // NOI18N
        btnDelete.setToolTipText(resourceMap.getString("btnDelete.toolTipText")); // NOI18N
        btnDelete.setName("btnDelete"); // NOI18N
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });
        pnlDefaultButtons.add(btnDelete);

        btnExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rad/Java/Common/Resources/exit_32x32.png"))); // NOI18N
        btnExit.setToolTipText(resourceMap.getString("btnExit.toolTipText")); // NOI18N
        btnExit.setName("btnExit"); // NOI18N
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });
        pnlDefaultButtons.add(btnExit);

        pnlFrame.add(pnlDefaultButtons, java.awt.BorderLayout.SOUTH);

        pnlMain.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pnlMain.setName("pnlMain"); // NOI18N
        pnlMain.setLayout(new java.awt.BorderLayout());

        tbpMain.setName("tbpMain"); // NOI18N
        tbpMain.setPreferredSize(new java.awt.Dimension(388, 324));

        pnlSearch.setName("pnlSearch"); // NOI18N

        lblSearch.setText(resourceMap.getString("lblSearch.text")); // NOI18N
        lblSearch.setName("lblSearch"); // NOI18N

        txtSearch.setName("txtSearch"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tblMain.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblMain.setName("tblMain"); // NOI18N
        jScrollPane1.setViewportView(tblMain);

        btnSearch.setText(resourceMap.getString("btnSearch.text")); // NOI18N
        btnSearch.setName("btnSearch"); // NOI18N
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlSearchLayout = new javax.swing.GroupLayout(pnlSearch);
        pnlSearch.setLayout(pnlSearchLayout);
        pnlSearchLayout.setHorizontalGroup(
            pnlSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlSearchLayout.createSequentialGroup()
                        .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnSearch))
                    .addComponent(lblSearch)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 355, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlSearchLayout.setVerticalGroup(
            pnlSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSearchLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblSearch)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSearch))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tbpMain.addTab(resourceMap.getString("pnlSearch.TabConstraints.tabTitle"), pnlSearch); // NOI18N

        pnlEdit.setName("pnlEdit"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        txtName.setText(resourceMap.getString("txtName.text")); // NOI18N
        txtName.setName("txtName"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        txtAddress.setText(resourceMap.getString("txtAddress.text")); // NOI18N
        txtAddress.setName("txtAddress"); // NOI18N

        try {
            txtPhone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtPhone.setName("txtPhone"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        try {
            txtDateBorn.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtDateBorn.setName("txtDateBorn"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        txtUsuario.setText(resourceMap.getString("txtUsuario.text")); // NOI18N
        txtUsuario.setName("txtUsuario"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        txtPasswordConf.setText(resourceMap.getString("txtPasswordConf.text")); // NOI18N
        txtPasswordConf.setName("txtPasswordConf"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        txtPassword.setText(resourceMap.getString("txtPassword.text")); // NOI18N
        txtPassword.setName("txtPassword"); // NOI18N

        javax.swing.GroupLayout pnlEditLayout = new javax.swing.GroupLayout(pnlEdit);
        pnlEdit.setLayout(pnlEditLayout);
        pnlEditLayout.setHorizontalGroup(
            pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlEditLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlEditLayout.createSequentialGroup()
                        .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtAddress, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE))
                            .addGroup(pnlEditLayout.createSequentialGroup()
                                .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel5)
                                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6)
                                    .addComponent(txtDateBorn, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))))
                        .addGap(26, 26, 26))
                    .addGroup(pnlEditLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addContainerGap(293, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEditLayout.createSequentialGroup()
                        .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtUsuario, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                            .addComponent(txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(txtPasswordConf, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                        .addGap(27, 27, 27))))
        );
        pnlEditLayout.setVerticalGroup(
            pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlEditLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDateBorn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlEditLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPasswordConf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );

        tbpMain.addTab(resourceMap.getString("pnlEdit.TabConstraints.tabTitle"), pnlEdit); // NOI18N

        pnlMain.add(tbpMain, java.awt.BorderLayout.CENTER);

        pnlFrame.add(pnlMain, java.awt.BorderLayout.LINE_START);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnlFrame, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlFrame, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-408)/2, (screenSize.height-433)/2, 408, 433);
    }// </editor-fold>//GEN-END:initComponents

    private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
        _status = Constants.stInsert;
        Functions.setButtons(buttons, _status);
        Functions.clearForm(this);

        if(tbpMain.getSelectedIndex() != 1)
            tbpMain.setSelectedIndex(1);

        new_event();
}//GEN-LAST:event_btnNewActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        boolean result;

        if(!Functions.DateValidation(txtDateBorn.getText(), "dd/MM/yyyy")){
            JOptionPane.showMessageDialog(rootPane, "Erro na data");
            return;
        }
        if( Functions.validateForm(this) && valid()) {
            setClass();
            //Save
            if( _status == Constants.stInsert ) {
                result = save();
            } else //Update
            {
                result = update();
            }


            if( result ) {
                JOptionPane.showMessageDialog(this, "Registro salvo com sucesso!",_title, JOptionPane.INFORMATION_MESSAGE);
                listEmployee.clear();
                fillDataGridView();
                _status = Constants.stBrowse;
                Functions.setButtons(buttons, _status);
            } else {
                if (Database.ErrorMessage.contains("duplicate key violates unique constraint"))
                    JOptionPane.showMessageDialog(this, "Erro ao tentar salvar o registro:\nRegistro já existe!!!.",_title, JOptionPane.ERROR_MESSAGE);
                else
                    JOptionPane.showMessageDialog(this, "Erro ao tentar salvar o registro:\n"+Database.ErrorMessage,_title, JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
        tbpMain.setSelectedIndex(0);
        Functions.setButtons(buttons, _status);

}//GEN-LAST:event_btnSaveActionPerformed

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        _status = Constants.stEdit;

        int index = tblMain.getSelectedRow();
        if (index >= 0) {
            Functions.clearForm(this);
            setEdits();
            tbpMain.setSelectedIndex(1);

            Functions.setButtons(buttons, _status);
        } else
            JOptionPane.showMessageDialog(this, "Por favor selecione um registro!", _title, JOptionPane.INFORMATION_MESSAGE);
        edit();
}//GEN-LAST:event_btnEditActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        _status = Constants.stBrowse;

        tbpMain.setSelectedIndex(0);
        Functions.clearForm(this);
        Functions.setButtons(buttons, _status);
}//GEN-LAST:event_btnCancelActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        int index = tblMain.getSelectedRow();
        if (index < 0) {
            JOptionPane.showMessageDialog(this, "Por favor selecione um registro!", _title, JOptionPane.WARNING_MESSAGE );
            return;
        }
        int dr = JOptionPane.showConfirmDialog(this, "Deseja realmente excluir o registro?",
                _title,
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        if( dr == JOptionPane.YES_OPTION ) {
            if( delete() ) {
                JOptionPane.showMessageDialog(this, "Registro excluido com sucesso!", _title, JOptionPane.INFORMATION_MESSAGE);
                //lisDefault.fillList();
                fillDataGridView();
            } else {
                if (Database.ErrorMessage.contains("violates foreign key constraint"))
                    JOptionPane.showMessageDialog(this,
                            "Erro ao tentar excluir o registro:\nRegistro já referenciado em outra tabela.",
                            _title, JOptionPane.ERROR_MESSAGE);
                else
                    JOptionPane.showMessageDialog(this,
                            "Erro ao tentar excluir o registro:\n"+Database.ErrorMessage,
                            _title, JOptionPane.ERROR_MESSAGE);
            }
        }
        _status = Constants.stBrowse;
        Functions.setButtons(buttons, _status);
}//GEN-LAST:event_btnDeleteActionPerformed

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
        exit();
        this.dispose();
}//GEN-LAST:event_btnExitActionPerformed

    private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
        find();
}//GEN-LAST:event_btnSearchActionPerformed

// <editor-fold defaultstate="collapsed" desc="Manual Methods">
    protected void new_event(){
        employee.clear();
        txtDateBorn.setText("");
        txtPassword.setText("");
        txtPasswordConf.setText("");
        txtPhone.setText("");
    }

    protected boolean save(){
	return employee.save();
    }

    protected boolean update(){
        return employee.update();
    }

    protected boolean edit(){
        return true;
    }

    protected boolean delete(){
        employee.setId(tblMain.getValueAt(tblMain.getSelectedRow(), 0).toString());
        return employee.delete();
    }

    protected void exit(){

    }

    protected void init(){

    }

    protected void fillDataGridView(){
        int tam=0;
        initTable();

        String data[] = new String[4];
        tam = listEmployee.count();
        for(int i = 0; i < tam; i++)
        {
            data[0] = listEmployee.get(i).getId();
            data[1] = listEmployee.get(i).getPersonName();
            data[2] = listEmployee.get(i).getPersonPhone1();
            data[3] = listEmployee.get(i).getPersonAddress();

            dtmMain.addRow(data);
            if (i == 0){
               dtmMain.removeRow(0);
            }
        }

        tblMain.setModel(dtmMain);
        tblMain.repaint();
    }

    protected void initTable(){
        String[] columns = new String[]{"Codigo","Nome", "Telefone", "Endereço"};
        String[][] data = new String[][]{{}};
        dtmMain = new DefaultTableModel(data, columns);
        tblMain.setModel(dtmMain);
    }

    protected void setEdits(){
        try {
            employee.setId(tblMain.getValueAt(tblMain.getSelectedRow(), 0).toString());
            if (employee.get()) {
                txtName.setText(employee.getPersonName());
                txtAddress.setText(employee.getPersonAddress());
                txtDateBorn.setText(employee.getPersonBornDate());
                txtPassword.setText(employee.getPersonPassword());
                txtPasswordConf.setText(employee.getPersonPassword());
                txtPhone.setText(employee.getPersonPhone1());
                txtUsuario.setText(employee.getPersonUsername());
            }
        } catch (SQLException ex) {
            Logger.getLogger(frmRegisterEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    protected void setClass(){
        employee.setPersonName(txtName.getText());
        employee.setPersonAddress(txtAddress.getText());
        employee.setPersonBornDate(txtDateBorn.getText());

        String aux = new String(txtPassword.getPassword());
        //aux = Functions.getMd5(aux);
        if(!aux.equals(employee.getPersonPassword()))
            employee.setPersonPassword(rad.Java.Common.Util.Functions.getMd5(aux));
        employee.setPersonPhone1(txtPhone.getText());
        employee.setPersonUsername(txtUsuario.getText());
    }

    protected void find(){
        listEmployee.fillListByName(txtSearch.getText());
        fillDataGridView();
    }

    protected boolean valid(){
        return true;
    }
// </editor-fold>

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    public javax.swing.JButton btnDelete;
    public javax.swing.JButton btnEdit;
    public javax.swing.JButton btnExit;
    public javax.swing.JButton btnNew;
    public javax.swing.JButton btnSave;
    private javax.swing.JButton btnSearch;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblSearch;
    protected javax.swing.JPanel pnlDefaultButtons;
    private javax.swing.JPanel pnlEdit;
    private javax.swing.JPanel pnlFrame;
    protected javax.swing.JPanel pnlMain;
    private javax.swing.JPanel pnlSearch;
    private javax.swing.JTable tblMain;
    private javax.swing.JTabbedPane tbpMain;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JFormattedTextField txtDateBorn;
    private javax.swing.JTextField txtName;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JPasswordField txtPasswordConf;
    private javax.swing.JFormattedTextField txtPhone;
    private javax.swing.JTextField txtSearch;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables

    protected  DefaultTableModel dtmMain;
    protected int _status;
    protected boolean  resizeForm = false;
    protected String _title;

    protected boolean tabSearchVisible = true;
    protected boolean tabMainVisible = true;
    protected JButton[] buttons = new JButton[6];
}
